package com.webservice_springboot.server.weather;

import org.springframework.stereotype.Service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 天气业务类
 */
@Service
@WebService
public class WeatherInterfaceImpl implements WeatherInterface {

    @Override
    @WebMethod(operationName = "queryWeather")
    @WebResult(name = "resList")
    public List<WeatherModel> queryWeather(@WebParam(name = "cityName") String cityName) throws Exception {
        //构造三天的天气结果
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DATE);

        List<WeatherModel> list = new ArrayList<>();
        list.add(WeatherModel.builder()
                .date(new Date())
                        .detail("晴朗")
                        .temperature_max(28)
                        .temperature_min(20)
                .build());
        calendar.set(Calendar.DATE, day + 1);
        list.add(WeatherModel.builder()
                .date(calendar.getTime())
                .detail("晴朗")
                .temperature_max(28)
                .temperature_min(20)
                .build());
        calendar.set(Calendar.DATE, day + 2);
        list.add(WeatherModel.builder()
                .date(calendar.getTime())
                .detail("晴朗")
                .temperature_max(28)
                .temperature_min(20)
                .build());
        //返回三天的天气
        return list;
    }
}
